package view.servlet.knowledge;

import com.alibaba.fastjson.JSON;
import pojo.Knowledge;
import pojo.User;
import pojo.vo.Message;
import service.KnowledgeService;
import service.impl.KnowledgeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author wq3stone
 */
@WebServlet("/queryKlg")
public class QueryKlg extends HttpServlet {
    KnowledgeService knowledgeService = new KnowledgeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String key = req.getParameter("key");
        String value = req.getParameter("value");
        User user = (User)req.getSession().getAttribute("user");
        Message message = knowledgeService.queryKlg(key,value,user.getId());
        resp.getWriter().print(JSON.toJSONString(message));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
